package com.ruoyi.project.business.tenantsocialsecurity.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.tenantsocialsecurity.request.AddTenantsocialSecurityRequest;
import com.ruoyi.project.business.tenantsocialsecurity.request.ListTenantsocialSecurityRequest;
import com.ruoyi.project.business.tenantsocialsecurity.request.UpdateTenantsocialSecurityRequest;
import com.ruoyi.project.business.tenantsocialsecurity.response.TenantsocialSecurityResponse;
import com.ruoyi.project.business.tenantsocialsecurity.service.ITenantsocialSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社保基本配置Controller
 * 
 * @author ${author}
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/business/tenantsocialsecurity")
public class TenantsocialSecurityController extends BaseController {
    @Autowired
    private ITenantsocialSecurityService tenantsocialSecurityService;

    /**
     * 查询社保基本配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListTenantsocialSecurityRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<TenantsocialSecurityResponse> list = tenantsocialSecurityService.selectTenantsocialSecurityList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出社保基本配置列表
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:export')")
    @Log(title = "社保基本配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListTenantsocialSecurityRequest request) {
        Long tenantId = getTenantId();
        List<TenantsocialSecurityResponse> list = tenantsocialSecurityService.selectTenantsocialSecurityList(request, tenantId);
        ExcelUtil<TenantsocialSecurityResponse> util = new ExcelUtil<>(TenantsocialSecurityResponse.class);
        return util.exportExcel(list, "tenantsocialsecurity");
    }

    /**
     * 获取社保基本配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tenantsocialSecurityService.selectTenantsocialSecurityById(id));
    }

    /**
     * 新增社保基本配置
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:add')")
    @Log(title = "社保基本配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddTenantsocialSecurityRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tenantsocialSecurityService.insertTenantsocialSecurity(request, operatorId, tenantId));
    }

    /**
     * 修改社保基本配置
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:edit')")
    @Log(title = "社保基本配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpdateTenantsocialSecurityRequest tenantsocialSecurity) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tenantsocialSecurityService.updateTenantsocialSecurity(tenantsocialSecurity, operatorId, tenantId));
    }

    /**
     * 删除社保基本配置
     */
    @PreAuthorize("@ss.hasPermi('business:tenantsocialsecurity:remove')")
    @Log(title = "社保基本配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tenantsocialSecurityService.deleteTenantsocialSecurityByIds(ids, operatorId, tenantId));
    }
}
